package com.tcl.hystrix.controller;

import com.tcl.api.response.UserResponse;
import com.tcl.hystrix.config.ExecuteFeignHystrix;
import com.tcl.hystrix.config.ObservableFeignHystrix;
import com.tcl.hystrix.feign.UserServiceFeignClient02;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author liuf
 * @Date 2020/12/17 16:37
 * @Description
 */
@RestController
@RequestMapping("/hystrix")
@Slf4j
public class HystrixController {


    @Autowired
    private UserServiceFeignClient02 userServiceFeignClient;

    @GetMapping("/get")
    public UserResponse test01() {
        ExecuteFeignHystrix executeFeignHystrix = new ExecuteFeignHystrix(userServiceFeignClient, 1);
        return executeFeignHystrix.execute();
    }

    @GetMapping("/get11")
    public UserResponse test011() {
        ObservableFeignHystrix observe = new ObservableFeignHystrix(userServiceFeignClient, 1);

        AtomicReference<UserResponse> userResponse = new AtomicReference<>(new UserResponse());
        observe.observe().subscribe(userResponse::set);
        return userResponse.get();
    }
}
